package com.ukao.steward.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.ukao.steward.R;
import com.ukao.steward.base.ListBaseAdapter;
import com.ukao.steward.base.SuperViewHolder;
import com.ukao.steward.bean.ShoppingBean;
import com.ukao.steward.util.CheckUtils;

import java.util.List;

/**
 * Created by ukaodev on 2017/8/24.
 */

public class ShoppCountAdapter extends ListBaseAdapter<ShoppingBean> {




    public ShoppCountAdapter(Context context, List<ShoppingBean> mHomeBean) {
        super(context, mHomeBean);
    }

    @Override
    public int getLayoutId() {
        return R.layout.adapter_shopp_count;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder,final int position) {
        ShoppingBean  item = mDataList.get(position);
        TextView serveName = holder.getView(R.id.serve_name);
        TextView pice = holder.getView(R.id.pice);
        TextView name = holder.getView(R.id.product_name);
        TextView count = holder.getView(R.id.count);
        Button addBtn = holder.getView(R.id.add_btn);
        Button subtractBtn = holder.getView(R.id.subtract_btn);
        pice.setText("￥"+CheckUtils.isEmptyNumber(item.getPrice()));
        name.setText(CheckUtils.isEmptyString(item.getName()));
        count.setText(item.getCount()+"");
        if (!CheckUtils.isEmpty(item.getSelectServiceName())){
            serveName.setVisibility(View.VISIBLE);
            serveName.setText("服务（"+item.getSelectServiceName()+")");
        }else{
            serveName.setVisibility(View.GONE);
        }

        View.OnClickListener   mOnClickListener= new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!CheckUtils.isNull(mOnItemChildClickListener)){
                    ShoppingBean  item = mDataList.get(position);
                    mOnItemChildClickListener.onChildItemClick(v.getId(),position,item);
                }
            }
        };
        subtractBtn.setOnClickListener(mOnClickListener);
        addBtn.setOnClickListener(mOnClickListener);
    }

}
